<template>
  <div class="mod-config">
    <el-form
      :inline="true"
      :model="queryInfo"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-input
          v-model="queryInfo.example.paramType"
          :placeholder="i18n['sys.config.field.paramType']"
          @change="condChange"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{
          i18n["gobal.button.search"]
        }}</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%"
    >
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        :label="i18n['sys.config.field.paramId.title']"
      >
      </el-table-column>
      <el-table-column
        prop="paramType"
        header-align="center"
        align="center"
        :label="i18n['sys.config.field.paramType.title']"
      >
      </el-table-column>
      <el-table-column
        prop="paramKey"
        header-align="center"
        align="center"
        :label="i18n['sys.config.field.paramKey.title']"
        >>
      </el-table-column>
      <el-table-column
        prop="paramValue"
        header-align="center"
        align="center"
        :label="i18n['sys.config.field.paramValue.title']"
        >>
      </el-table-column>
      <el-table-column
        prop="disableFlag"
        header-align="center"
        align="center"
        :label="i18n['gobal.field.disableFlag']"
      >
        <template slot-scope="scope">
          <el-tag
            v-if="scope.row.disableFlag === 1"
            size="small"
            type="danger"
            >{{ i18n["gobal.field.disableFlag.YES"] }}</el-tag
          >
          <el-tag v-else size="small">{{
            i18n["gobal.field.disableFlag.NO"]
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="description"
        header-align="center"
        align="center"
        @label="i18n['gobal.field.description']"
      >
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="queryInfo.page.pageNo"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="queryInfo.page.pageSize"
      :total="queryInfo.page.dataCount"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  inject: ["i18n"],
  data() {
    return {
      queryInfo: {
        example: {},
        page: {
          pageNo: 1,
          pageSize: 20,
          dataCount: null,
        },
      },
      dataList: [],
      dataListLoading: false,
    };
  },
  components: {},
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/sys/config/list"),
        method: "post",
        data: this.$http.adornData({
          page: this.queryInfo.page,
          example: this.queryInfo.example,
        }),
      })
        .then(({ data }) => {
          if (data && data.code === 200 && data.data && data.data.list) {
            this.dataList = data.data.list;
            this.queryInfo.page.dataCount = Number(data.data.page.dataCount);
          } else {
            this.dataList = [];
            this.queryInfo.page.dataCount = 0;
            this.$message.error(data.msg);
          }
          this.dataListLoading = false;
        })
        .catch((e) => {
          this.$message.error(e.message);
          this.dataListLoading = false;
        });
    },
    condChange(val) {
      this.queryInfo.page.pageNo = 1;
    },
    // 每页数
    sizeChangeHandle(val) {
      this.queryInfo.page.pageSize = val;
      this.queryInfo.page.pageNo = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.queryInfo.page.pageNo = val;
      this.getDataList();
    },
  },
};
</script>
